import React, {Component} from 'react';
import {connect} from 'react-redux';
import * as DataName from "../../action/DataNameConfig";
import { setCommonSystemLoading } from "../../action/Action";
import { GetSendPackage } from "../../action/ActionOrder";
import Util from "../../utils/Util";
import { Form, Modal, Input, Spin, DatePicker } from "antd";
const FormItem = Form.Item;

/**
 * 忘记密码
 * @export
 * @class ForgetPasswordModal
 * @extends {Component}
 */
class Main extends Component {
    constructor(props) {
        super(props);
        this.state={
            type:'text',
            loading:false,
        }
        this.handleSubmit=(e)=>{
            e.preventDefault();
            let {dispatch, BaseData} = this.props;
            this.props.form.validateFields((err, values) => {
                if (!err) {
                    let orderList = BaseData[DataName.ORDER_LIST] || {};
                    dispatch(setCommonSystemLoading(DataName.FORM_SPIN_LOADING,true));
                    values.order_no = this.props.orderNo || "";
                    values.pid = "";
                    dispatch(GetSendPackage(values,orderList.filter));
                }
            });
        }

        this.onCancel=()=>{
            let {dispatch} = this.props;
            dispatch(setCommonSystemLoading(DataName.BASE_MODAL,false));
        }
    }
    componentWillMount() {}
    render() {
        const {getFieldDecorator} = this.props.form;
        let { CommonSystem, BaseData} = this.props;
        return (
            <Modal
                visible={CommonSystem[DataName.BASE_MODAL] || false}
                title="发货"
                onOk={this.handleSubmit}
                onCancel={this.onCancel}
                width={400}
                style={{top: '35%'}}
                confirmLoading={CommonSystem[DataName.FORM_SPIN_LOADING] || false}
            >
                <Spin spinning={CommonSystem[DataName.FORM_SPIN_LOADING] || false} tip="正在更新">
                    <Form onSubmit={this.handleSubmit} style={{maxWidth: '340px', margin: '0 auto'}}>
                        <FormItem>
                            {getFieldDecorator('company', {
                                initialValue: '',
                                rules: [{required: true, message: '请输入快递公司', whitespace: true}],
                            })(
                                <Input placeholder="快递公司" />
                            )}
                        </FormItem>
                        <FormItem>
                            {getFieldDecorator('number', {
                                initialValue: '',
                                rules: [{required: true, message: '请输入快递单号', whitespace: true}],
                            })(
                                <Input type={this.state.type} placeholder="输入快递单号" onFocus={this.enterPass} />
                            )}
                        </FormItem>
                        <FormItem>
                            {getFieldDecorator('send_time', {
                                initialValue: '',
                                rules: [{required: true, message: '请输入发货时间'}],
                            })(
                                <DatePicker showTime format="YYYY-MM-DD HH:mm:ss" style={{width: '100%'}} />
                            )}
                        </FormItem>
                    </Form>
                </Spin>
            </Modal>
        );
    }
}
export default connect(state => ({
    BaseData: state.BaseData,
    CommonSystem: state.CommonSystem
}))(Form.create()(Main));
